package com.td.erhome.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.td.erhome.R;
import com.td.erhome.models.CostListBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2017/2/14.
 */

public class CostListAdapter extends RecyclerView.Adapter<CostListAdapter.MyViewHolder> {
    private Context mContext;
    List<CostListBean.HouseListBean> mData;

    public CostListAdapter(Context context, List<CostListBean.HouseListBean> data) {
        this.mContext = context;
        mData = data;
    }

    public void AddAllData(List<CostListBean.HouseListBean> data){
        mData.addAll(data);
        notifyDataSetChanged();
    }

    public void clearData(){
        mData.clear();
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = View.inflate(mContext, R.layout.cost_list_item, null);
        MyViewHolder holder = new MyViewHolder(itemView);
        return holder;
    }

    @Override

    public void onBindViewHolder(final MyViewHolder holder, final int position) {

        holder.mTvName.setText(mData.get(position).district_name);
        holder.mTvTime.setText(mData.get(position).tran_time);
        holder.mTvAcreage.setText(mData.get(position).house_dimensions);
        holder.mTvPrice.setText(mData.get(position).single_price);
        holder.mTvType.setText(mData.get(position).type_of_house);
        holder.mTvFitment.setText(mData.get(position).house_decoration_type_name);

    }


    @Override
    public int getItemCount() {
        return mData.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_time)
        TextView mTvTime;
        @Bind(R.id.tv_acreage)
        TextView mTvAcreage;
        @Bind(R.id.tv_price)
        TextView mTvPrice;
        @Bind(R.id.tv_type)
        TextView mTvType;
        @Bind(R.id.tv_fitment)
        TextView mTvFitment;
        @Bind(R.id.tv_name)
        TextView mTvName;


        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
